#include <iostream>
#include "initializer_list.h"

A::A(std::initializer_list<int> integers)
{
    m_vecIntegers.insert(m_vecIntegers.end(), integers.begin(), integers.end());
}

A::~A() {}

void A::append(std::initializer_list<int> integers)
{
    m_vecIntegers.insert(m_vecIntegers.end(), integers.begin(), integers.end());
}

void A::print()
{
    size_t size = m_vecIntegers.size();
    for (size_t i = 0; i < size; ++i) {
        std::cout << m_vecIntegers[i] << " ";
    }
    std::cout << "size:" << size << std::endl;
}

JsonNode::JsonNode(const char* k, const char* v)
    : type(JsonType::JsonTypeString)
    , key(k)
    , value(v)
{
    std::cout << "JsonNode constructor1 called, type:" << (int)type
              << ", key:" << key << ", value:" << value << std::endl;
}

JsonNode::JsonNode(const char* k, double v)
    : type(JsonType::JsonTypeDouble)
    , key(k)
    , value(std::to_string(v))
{
    std::cout << "JsonNode constructor2 called, type:" << (int)type
              << ", key:" << key << ", value:" << value << std::endl;
}

Json Json::m_json;
Json& Json::array(std::initializer_list<JsonNode> nodes)
{
    m_json.m_nodes.clear();
    m_json.m_nodes.insert(m_json.m_nodes.end(), nodes.begin(), nodes.end());
    std::cout << "Json::array() called, size:" << nodes.size() << std::endl;
    return m_json;
}

std::string Json::toString()
{
    std::string str;
    size_t size = m_nodes.size();
    for (size_t i = 0; i < size; ++i) {
        switch (m_nodes[i].type) {
            case JsonType::JsonTypeString:
                break;
            default:
                break;
        }
    }

    return str;
}